/**
 * Yolema.com Inc.
 * Copyright (c) 2011-2012 All Rights Reserved.
 */
package org.grayrabbit.pay.trade;

import java.io.Serializable;

import org.grayrabbit.pay.core.model.enums.PayResultEnum;
import org.grayrabbit.pay.core.model.exception.PayException;

/**
 * 货币交易
 * 
 * @author wy
 * @version $Id: Money.java, v 0.1 2012-6-1 下午5:36:08 wy Exp $
 */
public class TradeMoney implements Serializable{
    
    /** serialVersionUID */
    private static final long serialVersionUID = -6393578470033599829L;
    /**
     * 默认金钱数,单位分
     */
    private Long moneyFen = 0L;
    
    /**
     * 转换元
     * 
     * @param yuan
     * @return
     */
    public TradeMoney convertYuan(long yuan){
        moneyFen = yuan*100;
        return this;
    }
    
    /**
     * 转换分
     * @return
     */
    public TradeMoney convertFen(long fen){
        moneyFen = fen;
        return this;
    }
    
    
    /**
     * 获取银联需要的价钱信息
     * 
     * @return
     */
    public String getChinaPay(){
        
        String money = String.valueOf(moneyFen);
        //不能超过12位
        if(moneyFen<0||money.length()>12){
            throw new PayException(PayResultEnum.MONEY_ERROR);
        }
        while(money.length()<12){
            money = "0"+money;
        }
        return money;
    }

}
